package sample.controls;

import org.dreamwork.jasmine2.events.EventException;
import org.dreamwork.jasmine2.web.IWebControl;
import org.dreamwork.jasmine2.web.controls.WebContainer;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 11-8-24
 * Time: 下午9:48
 */
public class ShowOrNot extends WebContainer {
    @Override
    public IWebControl copy () {
        ShowOrNot copy = new ShowOrNot ();
        for (Iterator iter = getAttributeNames (); iter.hasNext ();) {
            String name = (String) iter.next ();
            String value = getAttribute (name);
            copy.setAttribute (name, value);
        }

        for (Iterator iter = getDynamicAttributeNames (); iter.hasNext ();) {
            String name = (String) iter.next ();
            String expression = getDynamicAttribute (name);
            copy.setDynamicAttribute (name, expression);
        }

/*
        for (int i = 0; i < childControls.count (); i ++) {
            copy.childControls.add (childControls.getKey (i), childControls.get (i).copy ());
        }
*/

        return copy;
    }

    @Override
    public void render (PrintWriter writer) throws IOException, EventException {
        if (!visible) return;

        for (int i = 0; i < childControls.count (); i ++) {
            childControls.get (i).render (writer);
        }
    }
}
